cmake_minimum_required(VERSION 3.11)
project(ZMQ_Modes)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 添加 ZeroMQ 依赖库
add_subdirectory(libs/libzmq-master)
include_directories(libs/libzmq-master/include)

# 添加 cppzmq 头文件目录，cppzmq 是头文件库
include_directories(libs/cppzmq)

# 添加全局的 include 目录
include_directories(include/PAIR-PAIR)
include_directories(include/PUB-SUB)
include_directories(include/PUSH-PULL)
include_directories(include/REQ-REP)
include_directories(include/DEALER-ROUTER)
include_directories(include/STREAM)

# 链接到 libzmq 库
find_package(Threads REQUIRED)
link_directories(${CMAKE_SOURCE_DIR}/libs/libzmq-master/build/lib)

# PAIR-PAIR 模式
add_executable(pair1 main/main_pair1.cpp src/PAIR-PAIR/pair.cpp)
target_link_libraries(pair1 zmq Threads::Threads)
add_custom_command(TARGET pair1 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pair1> ${PROJECT_SOURCE_DIR})

add_executable(pair2 main/main_pair2.cpp src/PAIR-PAIR/pair.cpp)
target_link_libraries(pair2 zmq Threads::Threads)
add_custom_command(TARGET pair2 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pair2> ${PROJECT_SOURCE_DIR})

# PUB-SUB 模式
add_executable(publisher main/main_publisher.cpp src/PUB-SUB/Publisher.cpp)
target_link_libraries(publisher zmq Threads::Threads)
add_custom_command(TARGET publisher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:publisher> ${PROJECT_SOURCE_DIR})

add_executable(subscriber main/main_subscriber.cpp src/PUB-SUB/subscriber.cpp)
target_link_libraries(subscriber zmq Threads::Threads)
add_custom_command(TARGET subscriber POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:subscriber> ${PROJECT_SOURCE_DIR})

# PUSH-PULL 模式
add_executable(push main/main_push.cpp src/PUSH-PULL/push.cpp)
target_link_libraries(push zmq Threads::Threads)
add_custom_command(TARGET push POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:push> ${PROJECT_SOURCE_DIR})

add_executable(pull main/main_pull.cpp src/PUSH-PULL/pull.cpp)
target_link_libraries(pull zmq Threads::Threads)
add_custom_command(TARGET pull POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pull> ${PROJECT_SOURCE_DIR})

add_executable(xpub_proxy main/main_xpub_proxy.cpp src/PUB-SUB/xpub_proxy.cpp)
target_link_libraries(xpub_proxy zmq Threads::Threads)
add_custom_command(TARGET xpub_proxy POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:xpub_proxy> ${PROJECT_SOURCE_DIR})

# REQ-REP 模式
add_executable(client main/main_client.cpp src/REQ-REP/client.cpp)
target_link_libraries(client zmq Threads::Threads)
add_custom_command(TARGET client POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:client> ${PROJECT_SOURCE_DIR})

add_executable(server main/main_server.cpp src/REQ-REP/server.cpp)
target_link_libraries(server zmq Threads::Threads)
add_custom_command(TARGET server POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:server> ${PROJECT_SOURCE_DIR})

#DEALER-ROUTER 模式
add_executable(router main/main_router.cpp src/DEALER-ROUTER/Router.cpp)
target_link_libraries(router zmq Threads::Threads)
add_custom_command(TARGET router POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:router> ${PROJECT_SOURCE_DIR})

add_executable(dealer main/main_dealer.cpp src/DEALER-ROUTER/Dealer.cpp)
target_link_libraries(dealer zmq Threads::Threads)
add_custom_command(TARGET dealer POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dealer> ${PROJECT_SOURCE_DIR})

#STREAM 模式
add_executable(stream_server main/main_stream_server.cpp src/STREAM/stream.cpp)
target_link_libraries(stream_server zmq Threads::Threads)
add_custom_command(TARGET stream_server POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:stream_server> ${PROJECT_SOURCE_DIR})

add_executable(stream_client main/main_stream_client.cpp src/STREAM/stream.cpp)
target_link_libraries(stream_client zmq Threads::Threads)
add_custom_command(TARGET stream_client POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:stream_client> ${PROJECT_SOURCE_DIR})